﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace MultiThread
{
    class Program
    {
        static void Main(string[] args)
        {
            var apple = new ApplePackage();
            apple.StartAdd();
            apple.StartGet();
            System.Console.ReadLine();
        }
    }

    public class ApplePackage
    {
        private static object _syncroot = new object();
        private List<string> _apples = new List<string>();
        private Thread _t1;
        private Thread _t2;

        public void StartAdd()
        {
            _t1 = new Thread(Add);
            _t1.Start();
        }

        public void StartGet()
        {
            _t2 = new Thread(Get);
            _t2.Start();
        }

        private void Add()
        {
            try
            {
                while (true)
                {
                    lock (_syncroot)
                    {
                        _apples.Add(Guid.NewGuid().ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                var s = ex.ToString();
            }
        }

        private void Get()
        {
            try
            {
                while (true)
                {
                    lock (_syncroot)
                    {
                        _apples.ToList();
                    }
                }
            }
            catch(Exception ex)
            {
                
                var s = ex.ToString();
            }
        }
    }
}
